Skip to content

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Feb 12, 2026

Adds brotli support to CompressionStream and DecompressionStream. After this change, almost all of the compression web-platform tests pass.

@anonrig anonrig requested review from a team as code owners February 12, 2026 01:38
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 23.48485% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.31%. Comparing base (6ff050c) to head (d655771).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/workerd/api/streams/compression.c++ 25.00% 82 Missing and 8 partials ⚠️
src/workerd/api/streams/internal.c++ 8.33% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6060      +/-   ##
==========================================
- Coverage   70.37%   70.31%   -0.06%     
==========================================
  Files         408      408              
  Lines      108811   108913     +102     
  Branches    18000    18030      +30     
==========================================
+ Hits        76574    76584      +10     
- Misses      21430    21515      +85     
- Partials    10807    10814       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell
Copy link
Collaborator

jasnell commented Feb 12, 2026

It seems the wpt's were added prematurely without being marked tentative. It's good to have this ready but let's hold off landing until it lands in the actual spec.

Copy link
Collaborator

@jasnell jasnell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the fact that brotli has not been added to the spec yet, several issues with the impl as is. It looks like there are some bits here in internal.c++ that have nothing to do with brotli that are possibly breaking. Those would be separated out to a different pr.

break;
}
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like an odd way to structure this when there's already a switch body here. Seems they can be coalesced.

if (format == "deflate") return Format::DEFLATE;
if (format == "deflate-raw") return Format::DEFLATE_RAW;
if (format == "brotli") return Format::BROTLI;
KJ_UNREACHABLE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really unreachable. This should probably throw a proper exception, just in case

static int getWindowBits(kj::StringPtr format) {
void initBrotli() {
if (mode == Mode::COMPRESS) {
auto* instance = BrotliEncoderCreateInstance(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more idiomatic to wrap the unit/cleanup into a smart pointer

size_t brotliAvailIn = 0;
// Brotli state structs are opaque, so kj::Own would require complete types.
BrotliEncoderState* brotliEncoderState = nullptr;
BrotliDecoderState* brotliDecoderState = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a fan of the use of raw pointers in here. This should be using kj::Owns and kj::Arrays etc.

JSG_REQUIRE(
format == "deflate" || format == "gzip" || format == "deflate-raw" || format == "brotli",
TypeError,
"The compression format must be either 'deflate', 'deflate-raw', 'gzip', or 'brotli'.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to call the function that parses these and have that throw the error directly to avoid the double string comparisons

// This case caused me a moment of confusion during testing, so I think it's worth
// a specific error message.
throwTypeErrorAndConsoleWarn(
return rejectInvalidChunk(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavioral change that might require a compat flag I believe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants